<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>例题</title>
    <style>
        div{
            box-sizing;
        }
    </style>
</head>
<body>
    <div><img src="" alt=""></div>
    <script>
        
//例题1：将数组里每个对象的名字年龄分别取出，放入新数组中华
    /*
    var oldArr = [
        {
            name:"fyr",
            age:18
        },
        {
            name:"zmq",
            age:22
        },
        {
            name:"xxx",
            age:30
        },
    ]
    //forEach方法

    var name_arr = [];
    var age_arr = [];
    oldArr.forEach(function(item,index){
        console.log(item)
        name_arr.push(item.name);
        age_arr.push(item.age)
    })
    console.log(name_arr,age_arr)
    
    //map方法
    var name_arr = oldArr.map(function(item,index){
        return item.name
    });
    var age_arr = oldArr.map(function(item,index){
        return item.age
    });
    console.log(name_arr,age_arr)
    */
//例题2  查找e在字符串中的所有位置：
    // var str = 'He unfolded the map and set it on the floor';
    // var arr = [];
    // var pos = str.indexOf('e');
    // while(pos > -1){
    //     arr.push(pos);
    //     pos = str.indexOf('e',pos+1)
    // }
    // console.log(arr)
    
//例三 1 获取min到max之间的整数
        // var max = Math.max(1,2,3,4,5,6);
        // alert(max)
        // var min = Math.min(1,2,3,4,5,6);
        // alert(min)
        // var rand = Math.random() * (max-min) + min;
        // alert(rand)
        function random(min,max){
            return Math.floor(Math.random() * (max-min) + min);
        }
    //  2 获取随机颜色 rgb(0-255,0-255,0-255)
        // var a = Math.random()*255;
        // var red = Math.round(a);
        // var b = Math.random()*255;
        // var blue = Math.round(b);
        // var c = Math.random()*255;
        // var green = Math.round(c);
        // alert(red+','+blue+','+green)

        // function rendomColor(){
        //     var r = random(0,256),g = random(0,256),b = random(0,256);
        //     var result = 'rgb'+'('+r+','+g+','+b+')';
        //     // var result ='rgb(${r},${g},${b})';
        //     return result;
        // }
        // var rc = rendomColor()
        // console.log(rc)
        // document.body.style.backgroundColor = rc
        
    //3  随机验证码
        function creatCode(){
            var code = '';
            var codeLength = 4;
            var ran = [0,1,2,3,4,5,6,7,8,9,
            'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z']
            for(var i=0;i<codeLength;i++){
                code = code + ran[random(0,36)];
            }
            return code;
        }
        var a = creatCode()
        alert(a)
    
    //截取form表单字符串
    // function get_user_pwd(){
    //     var up = location.search.length > 0 ? location.search :'';
    //     up = up.slice(1).split('&')
    //     var item=null,name=null,value=null,args={};
    //     for(i=0;i<up.length;i++){
    //     item = up[i].split('=');
    //     name = decodeURIComponent(item[0]);
    //     value = decodeURIComponent(item[1]);
    //     if(name.length){
    //         args[name]=value;
    //     }
    // }
    // return args;
    // }
    // var a = get_user_pwd();
    // console.log(a.user)
    // console.log(a.pwd )

    // 显示时间的网页
    // var now = new Date()
    //     document.write(now.toString())
    //     setInterval(function(){
    //         location.reload()
    //     }, 1000);

    </script>
        <!-- <form>
            <input type="text" name="user">账号
            <input type="password" name="pwd">密码
            <input type="submit">
        </form> -->
</body>
</html>